//
//  YQPCouponCell.m
//  MuYing
//
//  Created by caominglei on 2020/6/4.
//  Copyright © 2020 TBB. All rights reserved.
//

#import "YQPCouponCell.h"

@implementation YQPCouponCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setUpSubviews];
        
        [self setUpSubviewsMasonry];

    }
    return self;
}
- (void)setUpSubviews
{
    _couponIcon = UIImageView.new;
    _couponIcon.layer.cornerRadius = 4;
    _couponIcon.layer.masksToBounds = YES;
    _couponIcon.backgroundColor = kAPPThemeColor;
    [self.contentView addSubview:_couponIcon];
    
    _couponName = UILabel.new;
    _couponName.text = @"店铺名称";
    _couponName.font = kSystemMedium(15);
    _couponName.textAlignment = NSTextAlignmentLeft;
    _couponName.textColor = HexColor(0x515151);
    [self.contentView addSubview:_couponName];

    _couponTime = UILabel.new;
    _couponTime.text = @"2018/06/06-2019/06/01";
    _couponTime.font = kSystemMedium(11);
    _couponTime.textAlignment = NSTextAlignmentLeft;
    _couponTime.textColor = HexColor(0xA0A0A0);
    [self.contentView addSubview:_couponTime];

    _couponPrice = UILabel.new;
    _couponPrice.textAlignment = NSTextAlignmentCenter;
    [_couponPrice rz_colorfulConfer:^(RZColorfulConferrer * _Nonnull confer) {
        confer.text(@"$ ").font(kSystemMedium(15)).textColor(HexColor(0xFFFFFF));
        confer.text(@"20").font(kSystemMedium(32)).textColor(HexColor(0xFFFFFF));
    }];
    [self.couponIcon addSubview:_couponPrice];
    
    _couponProfit = UILabel.new;
    _couponProfit.text = @"满100可用";
    _couponProfit.font = kSystemMedium(11);
    _couponProfit.textAlignment = NSTextAlignmentCenter;
    _couponProfit.textColor = HexColor(0xFFFFFF);
    [self.couponIcon addSubview:_couponProfit];
    
    _selectBtn = UIButton.new;
    [_selectBtn setImage:IMAGE_NAMED(@"coupon_normal") forState:UIControlStateNormal];
    [_selectBtn setImage:IMAGE_NAMED(@"coupon_select") forState:UIControlStateSelected];
    [_selectBtn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_selectBtn];

    _bgview = UIView.new;
    _bgview.backgroundColor = HexColor(0xF4F4F4);
    [self.contentView addSubview:_bgview];
}

- (void)onClick:(UIButton *)button
{
//    button.selected = !button.selected;
}

- (void)setUpSubviewsMasonry
{
    [self.couponIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(107);
        make.height.mas_equalTo(86);
        make.left.mas_equalTo(12);
        make.centerY.mas_equalTo(self.contentView);

    }];
    
    [self.couponName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.couponIcon.mas_right).offset(8);
        make.top.mas_equalTo(self.couponIcon.mas_top).offset(18);

    }];
    
    [self.couponTime mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.couponIcon.mas_right).offset(8);
        make.top.mas_equalTo(self.couponName.mas_bottom).offset(20);

    }];
    
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-24);
        make.centerY.mas_equalTo(self.contentView);
        make.width.height.mas_equalTo(20);
    }];
    
    [self.couponPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(7);
        make.centerX.mas_equalTo(self.couponIcon);
        make.left.width.mas_equalTo(self.couponIcon);
    }];
    
    [self.couponProfit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.couponPrice.mas_bottom);
        make.centerX.mas_equalTo(self.couponIcon);
        make.left.width.mas_equalTo(self.couponIcon);
    }];
    
    [self.bgview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.contentView.mas_bottom);
        make.left.right.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1);
    }];
}

- (void)setModel:(YQPCouponModel *)model
{
    _model = model;
    self.couponName.text = model.name;
    self.couponTime.text = [NSString stringWithFormat:@"%@%@",kYQLS(@"有效期至"),model.endTime];
    [_couponPrice rz_colorfulConfer:^(RZColorfulConferrer * _Nonnull confer) {
        confer.text(@"HKD ").font(kSystemMedium(15)).textColor(HexColor(0xFFFFFF));
        confer.text(model.discountsAmount).font(kSystemMedium(32)).textColor(HexColor(0xFFFFFF));
    }];
    self.couponProfit.text = [NSString stringWithFormat:@"%@%@%@",kYQLS(@"满"),model.minPoint,kYQLS(@"可用")];
    
    self.selectBtn.selected = model.isSelect;
}


@end
